package com.example.demo.json.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.json.dto.Json;
import com.example.demo.json.dto.YuanDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/zhuan")
public class xin {

    @GetMapping("/xin")
    public JSONObject jsonObject(@RequestBody YuanDto yuanDto){
        List<Json> yuanDtos = yuanDto.getList();
        Map<String, Object> map = new HashMap<>();
        for (Json jsonObject:yuanDtos) {
            if (jsonObject.getLevel().equals("district")){
                Map<String, Object> map1 = new HashMap<>();
                map1.put("adcode",jsonObject.getAdcode());
                map1.put("level",jsonObject.getLevel());
                map1.put("name",jsonObject.getName());
                map.put(jsonObject.getName(),map1);
            }
        }
        JSONObject jsonObject = new JSONObject(map);
        return jsonObject ;
    }

}
